package com.per.mybootall.excel.Controller;

import com.per.mybootall.excel.po.StudentsPo;
import com.per.mybootall.excel.utils.ExcelUtils;
import org.apache.http.HttpResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

/**
 * Excel的controller
 * */
@RestController
public class ExcelController {
    @GetMapping(value = "ExcelOut")
    public void excelOut(HttpServletResponse httpResponse) throws IOException {
        List<StudentsPo> list=new ArrayList<>();
        list.add(new StudentsPo("齐可1号","11111"));
        list.add(new StudentsPo("齐可2号","22222"));
        list.add(new StudentsPo("齐可3号","33333"));

        httpResponse.setContentType("application/vnd.ms-excel");
        httpResponse.setHeader("Content-Disposition","attachment ; filename=" + new String("啊实打实大苏打".getBytes(StandardCharsets.UTF_8),"ISO8859-1"));

        ExcelUtils.writeExcel(httpResponse,list);
    }
}
